﻿/// <reference path="../Scripts/jquery-2.0.3.intellisense.js" />
/// <reference path="../Scripts/angular.js" />

var app = angular.module("app", []);

app.controller("mainCtrl", function ($scope, mangSvc) {
    $scope.itemList = mangSvc.returntFn();

    $scope.distroyFnScope = function () {
        mangSvc.destroyFn();
    };
});

app.factory("mangSvc", function ($rootScope) {
    var items = [];
    var counter = 0;
    function start() {
        addInterval = setInterval(addItem, 500);
    }

    function addItem() {
        counter++;

        var obj = {
            nameIt: counter,
            time: "Hello"
        };

        items.push(obj);
        console.log(items);
        $rootScope.$apply();
    }
    start();

    function destroyScope() {
        clearInterval(addInterval);
    }


    return {
        returntFn: function () {
            return items;
        },
        destroyFn: function () {
            return destroyScope();
        }
    };
});






